<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>服务站点列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">

                        <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                        <script type="text/html" id ="test-table-reload-toolbar">
                            <button class="layui-btn layui-btn-sm #{if !toolsUtils.checkBtn('/station/add')} layui-hide #{/if}" lay-event="addStation"><i class="layui-icon layui-icon-add-circle-fine"></i>添加服务点</button>
                            <button class="layui-btn layui-btn-sm #{if !toolsUtils.checkBtn('/station/faultUserList') } layui-hide #{/if}" lay-event="notice"><i class="layui-icon layui-icon-notice"></i>异常通知人员</button>
                        </script>

                        <script type="text/html" id="test-table-reload-barDemo">
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/station/edit')} layui-hide #{/if}" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/station/faultRecordList')} layui-hide #{/if}" lay-event="record"><i class="layui-icon layui-icon-read"></i>异常记录</a>
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/station/fboxReSet')} layui-hide #{/if}" lay-event="reset"><i class="layui-icon layui-icon-util"></i>设备复位</a>
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/station/downQr')} layui-hide #{/if}" lay-event="down"><i class="layui-icon layui-icon-download-circle"></i>二维码</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','utils', 'form'], function(){
        var $ = layui.$,
                table = layui.table,
                form = layui.form,
                admin = layui.admin;

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,url: "/station/getStationList"
            ,toolbar: '#test-table-reload-toolbar'
            ,defaultToolbar:['filter']
            ,cellMinWidth: 80
            ,cols: [[
                {field:'id', title: '站点ID', fixed: true}
                , {field:'name', title: '站点名称'}
                , {field:'price', title: '服务金额'}
                , {field:'discountRate', title: '余额折扣', templet: function (d) {
                    return "<div>"+d.discountRate+"折</div>";
                }}
                , {field:'openStatusName', title: '营业状态'}
                , {field:'openTimeDesc', title: '营业时间'}
                , {field:'address', title: '营业地址'}
                , {field:'createTime', title: '创建时间',sort: true,templet: function (d) {
                        return "<div>"+layui.toDateString(d.createTime)+"</div>";
                    }}
                , {field:'successCount', title: '累计服务'}
                , {field:'income', title: '累计服务收入'}
                , {field:'deviceStatus', title: '设备运行状态',templet: function (d) {
                        if(d.deviceStatus===0){
                            return  "<a class=\"layui-btn layui-btn-xs\" lay-event=\"readStatus\">正常</a>";
                        }else{
                            return  "<a class=\"layui-btn layui-btn-xs layui-btn-danger\" lay-event=\"readStatus\">故障</a>";
                        }
                    }}
                , {fixed: 'right', title:'操作', toolbar: '#test-table-reload-barDemo', width: 350}
            ]]
            ,page: true
            ,height: 522
        });

        //头工具栏事件
        table.on('toolbar(test-table-reload)', function (obj) {
            if (obj.event === 'addStation') {
                window.location.href = "/station/add";
            } else if (obj.event === 'notice') {
                parent.layui.index.openTabsPage("/station/faultUserList", "异常通知人员");
            }
        });

        //监听行工具事件
        table.on('tool(test-table-reload)', function(obj){
            var data = obj.data;
            if (obj.event === 'edit') {
                window.location.href = "/station/edit?id=" + data.id;
            } else if (obj.event === 'readStatus') {
                layer.open({
                    type: 2
                    ,title: "设备运行状态"
                    ,content: '/station/readDeviceStatus?washDeviceStatus='+data.washDeviceStatus+'&enterGateStatus='+data.enterGateStatus +'&exitGateStatus='+ data.exitGateStatus
                    ,area: ['400px', '300px']
                    ,btn: ['关闭']
                });
            } else if (obj.event === 'record') {
                parent.layui.index.openTabsPage("/station/faultRecordList?name=" + data.name + "&stationId=" + data.id, "异常记录");
            } else if (obj.event === 'reset') {
                if (data.deviceStatus === 0){
                    layer.confirm('设备正常，是否强制复位设备？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4, btn: ['强制复位', '取消'] }, function () {
                        $.get("/station/fboxReSet?id=" + data.id, function (result) {
                            if (result.code > 0) {
                                layer.msg(result.msg, {icon: 2});
                            } else {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }
                        });
                    });
                } else {
                    layer.confirm('设备异常，是否确定复位设备？', {icon: 7, title: '提示', skin: 'layui-layer-molv', anim: 4, btn: ['确定复位', '取消'] }, function () {
                        $.get("/station/fboxReSet?id=" + data.id, function (result) {
                            if (result.code > 0) {
                                layer.msg(result.msg, {icon: 2});
                            } else {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }
                        });
                    });
                }
            } else if (obj.event === 'down') {
                var data = obj.data;
                var id= data.id;
                layer.open({
                    type: 2
                    ,title: '下载站点二维码'
                    ,content: '/station/downQr?id='+id
                    ,area: ['300px', '200px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        layer.close(index); //关闭弹层
                    }
                });
            }
        });

    });
</script>
</body>
</html>